﻿using System;
using System.Data;
using HRM.Common;
namespace HRM.BusinessLogic
{
    public class RateInfo : Standard_Info
    {
        public RateInfo()
        {
            _Rate_Remain = (Decimal)Null.SetNullValue(_Rate_Remain);
        }

        private Int32 _Rate_Id;
        public Int32 Rate_Id
        {
            get { return _Rate_Id; }
            set { _Rate_Id = value; }
        }

        private DateTime _Rate_Month;
        public DateTime Rate_Month
        {
            get { return _Rate_Month; }
            set { _Rate_Month = value; }
        }

        private Decimal _Rate_Social;
        public Decimal Rate_Social
        {
            get { return _Rate_Social; }
            set { _Rate_Social = value; }
        }

        private Decimal _Rate_Medical;
        public Decimal Rate_Medical
        {
            get { return _Rate_Medical; }
            set { _Rate_Medical = value; }
        }

        private Decimal _Rate_Unemployed;
        public Decimal Rate_Unemployed
        {
            get { return _Rate_Unemployed; }
            set { _Rate_Unemployed = value; }
        }

        private Decimal _Rate_Remain;
        public Decimal Rate_Remain
        {
            get { return _Rate_Remain; }
            set { _Rate_Remain = value; }
        }

        private String _Rate_Description;
        public String Rate_Description
        {
            get { return _Rate_Description; }
            set { _Rate_Description = value; }
        }
    }

    public class Rate_Controller : Standard_Controller
    {
        #region "Contructor"
        private static Rate_Controller _instance;
        protected Rate_Controller() { }
        protected void Dispose()
        {
            _instance = null;
        }
        private static object _syncLock = new object();
        public static Rate_Controller Instance()
        {
            if (_instance == null)
            {
                lock (_syncLock)
                {
                    if (_instance == null)
                        _instance = new Rate_Controller();
                }
            }
            return _instance;
        }
        public static Rate_Controller Instance(String transName)
        {
            if (!String.IsNullOrEmpty(transName))
            {
                Rate_Controller _instanceTrans = new Rate_Controller();
                _instanceTrans.Trans_Name = transName;
                return _instanceTrans;
            }
            else
                return Instance();
        }
        #endregion

        public const String cs_Table_Name = "HRM_Rate";

        public int Rate_Using(int RateID)
        {
            return Globals.Object_GetValue<int>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, "HRM_Rate_Using", RateID));
        }

        public DataSet Rate_GetAll()
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, "HRM_Rate_GetAll");
        }

        public DataSet Rate_GetList(out int ItemCount, int currentPage, int pageSize)
        {
            ItemCount = 0;
            DataSet ds= DataConnect.ExecuteDataset(DataConnect.WorkingConnect, "HRM_Rate_GetList", currentPage, pageSize);
            if (ds != null && ds.Tables.Count > 0)
            {
                ItemCount = Globals.DB_GetValue<int>(ds.Tables[1].Rows[0][0]);
            }
            return ds;
        }

        public RateInfo Rate_GetInfo(int RateID)
        {
            return CBO.FillObject<RateInfo>(DataConnect.ExecuteRow(DataConnect.WorkingConnect, "HRM_Rate_GetInfo", RateID));
        }

        public RateInfo Rate_GetInfoByDate(DateTime _DateVal)
        {
            return CBO.FillObject<RateInfo>(DataConnect.ExecuteRow(DataConnect.WorkingConnect, "HRM_Rate_GetByDate", _DateVal));
        }

        public RateInfo Rate_GetMax()
        {
            return CBO.FillObject<RateInfo>(DataConnect.ExecuteRow(DataConnect.WorkingConnect, "HRM_Rate_GetMax"));
        }

        public int Rate_Insert(RateInfo eInfo)
        {
            return Globals.Object_GetValue<int>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, "HRM_Rate_Insert", eInfo.Rate_Month, eInfo.Rate_Social, eInfo.Rate_Medical, eInfo.Rate_Unemployed, eInfo.Rate_Remain, eInfo.Rate_Description));
        }

        public bool Rate_Update(RateInfo eInfo)
        {
            //return Globals.Object_GetValue<bool>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, "HRM_Rate_Update", eInfo.Rate_Id, eInfo.Rate_Month, eInfo.Rate_Social, eInfo.Rate_Medical, eInfo.Rate_Unemployed, eInfo.Rate_Remain, eInfo.Rate_Description));
            return Globals.Object_GetValue<int>(DataConnect.ExecuteNonQuery(DataConnect.WorkingConnect, "HRM_Rate_Update", eInfo.Rate_Id, eInfo.Rate_Month, eInfo.Rate_Social, eInfo.Rate_Medical, eInfo.Rate_Unemployed, eInfo.Rate_Remain, eInfo.Rate_Description)) > 0;
            //return true;
        }

        public bool Rate_CheckDate(DateTime _FromDate, DateTime _ToDate)
        {
            return Globals.Object_GetValue<bool>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, "HRM_Rate_CheckDate", _FromDate, _ToDate));
        }

        public bool Rate_Delete(int RateID)
        {
            return Globals.Object_GetValue<bool>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, "HRM_Rate_Delete", RateID));
        }
    }
}

